package com.wss.common.wechat.util.weixin;



import com.wss.common.context.util.SystemConfig;
import com.wss.common.wechat.util.aes.AesException;
import com.wss.common.wechat.util.aes.WXBizMsgCrypt;

/**
 * @author 赵飞
 * @version V1.0
 * @Title:
 * @Package demo
 * @Description:
 * @date 2017/2/15
 */
public class DecryptUtil {




	/**
	 *密文：
	 timestamp=[1487152598];nonce=[778792762];encrypt_type=[aes];msg_signature=[262f90480be27dc163e40b6c9fd1ec47dea28a5e]接收到微信输入流,准备处理...
	 <xml><AppId><![CDATA[wx964f044ff3a4e329]]></AppId><Encrypt><![CDATA[ZuhnHddEs39jp+tgRyalmEoTpkfEgrS9sKI3VzcZaplOQ5QF7y+2YaJP1BY0cQFvoM0JpOV2XT8rzLzfweW0jIb61ouMBxqmTKogu413dzWAXqGBgVgB+7LN0TFkeOAgpe5lSu070KeIVdw0V6mWRdYBPUJBGVWgrUTYGiRJmoK+7MGhMBg38/l1UKO8wd9k7pcgL+1/K87WeMLJKP4joQLaXcdBCXjaXpykDZ1OAInPSEdEeFP96vqFnvHoM9c0w5BdS8CTqIyZud8nEyX2tjAZtnUQmLPoKrNOzO9/11yjiM0FKd33Yny/LA82XtTVOG0EVyPxTfAFI4Vhp3yzvJALt8uBB8RbUpEjDaAvzrrFeajhGaWTS7MJiHRqV+DUoXUagPQFds7CHEQb7vrjUCWPdWT5nJjW45H6iH435hG5F/0Q/nPL//MatCExsPWWLBo7VZsfkCsnOqYGeirCZw==]]></Encrypt></xml>
	 */

	/**
	 * 解密后:
	 * <xml><AppId><![CDATA[wx964f044ff3a4e329]]></AppId>
	 <CreateTime>1487152598</CreateTime>
	 <InfoType><![CDATA[component_verify_ticket]]></InfoType>
	 <ComponentVerifyTicket><![CDATA[ticket@@@GfGtRkgbkrDWlQe7RmERX7IE8_29nZBRRNmTqDxq9Ja0FI0ZpxD-j9XJPkxHEj1nSMC-lnyos6gR9jPO5uNG5g]]></ComponentVerifyTicket>
	 </xml>
	 */

	/**
	 * 进行消息推送密文解密测试
	 */
	public static String decryptMsg(String msgSignature,String timestamp,String nonce,String fromXML) throws AesException {
		String token = SystemConfig.getComponentToken();
		String encodingAesKey = SystemConfig.getEncodingAesKey();
		String appId = SystemConfig.getComponentAppId();

		WXBizMsgCrypt pc = new WXBizMsgCrypt(token, encodingAesKey, appId);
		String result = pc.decryptMsg(msgSignature, timestamp, nonce, fromXML);
		return result;
	}

}
